home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / Gimp / Compat.pm next >
Encoding:
Perl POD Document  |  2003-01-14  |  3.8 KB  |  149 lines

  1. =head1 NAME
  2.  
  3.  Gimp::Compat - compatibility functions for older versions of Gimp.
  4.  
  5. =head1 SYNOPSIS
  6.  
  7.  <loaded automatically on demand>
  8.  
  9. =head1 DESCRIPTION
  10.  
  11. Older versions of Gimp (version 1.0 at the time of this writing) lack some
  12. very important or useful functions.
  13.  
  14. This module is providing the most needed replacement functions. If you
  15. happen to miss a function then please create a replacement function and
  16. send it to me ;)
  17.  
  18. These functions are handled in exactly the same way as PDB-Functions,
  19. i.e. the (hypothetical) function C<gimp_image_xyzzy> can be called as
  20. $image->xyzzy, if the module is available.
  21.  
  22. =head1 FUNCTIONS
  23.  
  24. =over 4
  25.  
  26. =item gimp_text_fontname, gimp_get_extents_fontname
  27.  
  28. These are emulated in 1.0.
  29.  
  30. =item gimp_paintbrush
  31.  
  32. The last two arguments only available in 1.1 are simply dropped.
  33.  
  34. =back
  35.  
  36. =head1 AUTHOR
  37.  
  38. Various, Dov Grobgeld <dov@imagic.weizmann.ac.il>. The author of the
  39. Gimp-Perl extension (contact him to include new functions) is Marc Lehmann
  40. <pcg@goof.com>
  41.  
  42. =cut
  43.  
  44. package      Gimp::Compat;
  45.  
  46. $VERSION=1.211;
  47.  
  48. use Gimp ('croak', '__');
  49.  
  50. # as a failsafe check, lowest version NOT requiring this module
  51. @max_gimp_version = (1,1);
  52.  
  53. # The following function is used to convert a xlfd to the array structure
  54. # used by the pre 1.2 functions gimp_text_ext() and gimp_text_get_extent_ext().
  55.           
  56. sub xlfd_unpack {
  57.     my $fontname = shift;
  58.     my $size_overload = shift;
  59.     my $size_unit_overload = shift;
  60.     # XLFDs fields can contain anything, including minus signs, but we
  61.     # gracefully ignore these weird things here ;)
  62.     my $p = "[^-]*";
  63.     my($foundry,
  64.          $family,
  65.            $weight,
  66.               $slant,
  67.                  $set_width,
  68.                     $pixelsize,
  69.                        $pointsize, 
  70.                           $spacing,
  71.                              $registry,
  72.                                 $encoding,
  73.       ) = $fontname=~
  74.      /^-($p)     (?# foundry )
  75.        -($p)     (?# family  )
  76.        -($p)     (?# weight  )
  77.        -($p)     (?# slant   )
  78.        -($p)     (?# set_Width )
  79.        -$p       
  80.        -($p)     (?# pixelsize )
  81.        -($p)     (?# pointsize )
  82.        -$p      
  83.        -$p       
  84.        -($p)     (?# spacing )
  85.        -$p
  86.        -($p)     (?# rgstry )
  87.        -($p)     (?# encdng )
  88.      /x or die __"xlfd_unpack: unmatched XLFD '$fontname'\n";
  89.  
  90.     my $size;
  91.     if ($pixelsize && $pixelsize ne "*") {
  92.     $size = $pixelsize;
  93.     } else {
  94.     $size = 0.1*$pointsize;
  95.     }
  96.     $size = $size_overload if $size_overload;
  97.     my $size_unit = ($pointsize > 0);
  98.     $size_unit = $size_unit if defined $size_unit_overload;
  99.     return ($size, $size_unit, $foundry, $family, $weight, $slant,
  100.         $set_width, $spacing, $registry, $encoding);
  101. }
  102.  
  103. sub fun {
  104.    my($major,$minor,$name,$sub)=@_;
  105.    if (Gimp->major_version < $major
  106.        || (Gimp->major_version == $major && Gimp->minor_version < $minor)) {
  107.       *{"Gimp::Lib::$name"}=$sub;
  108.    }
  109. }
  110.  
  111. fun 1,1,gimp_text_get_extents_fontname,sub {
  112.    my($string, $xlfd_size, $xlfd_unit, $xlfd) = @_;
  113.    
  114.    Gimp->text_get_extents_ext($string, @font_info,
  115.                               xlfd_unpack($xlfd, $xlfd_size, $xlfd_unit));
  116. };
  117.     
  118. fun 1,1,gimp_text_fontname,sub {
  119.    my $img = shift if $_[0]->isa('Gimp::Image');
  120.    my ($drw, $x,$y, $string,$border,$antialias, $xlfd_size, $xlfd_unit, $xlfd) = @_;
  121.    my @params;
  122.  
  123.    if (!defined $drw || $drw == -1) {
  124.        $drw = undef;
  125.        @params = ($img);
  126.    }
  127.  
  128.    push(@params, $drw, $x, $y, $string, $border, $antialias,
  129.     xlfd_unpack($xlfd, $xlfd_size, $xlfd_unit));
  130.    
  131.    Gimp->text_ext(@params);
  132. };
  133.  
  134. fun 1,1,gimp_paintbrush,sub {
  135.    shift if $_[0]->isa('Gimp::Image');
  136.    my $drawable = shift;
  137.    my $fade_out = shift;
  138.    shift unless ref $_[0];
  139.    my $strokes = shift;
  140.    Gimp::gimp_call_procedure('gimp_paintbrush',$drawable,$fade_out,$strokes);
  141. };
  142.  
  143. fun 1,1,gimp_image_list,sub {
  144.    Gimp::gimp_call_procedure('gimp_list_images');
  145. };
  146.  
  147. 1;
  148.  
  149.